<?php
class IndexAction extends Action {

	/**
	 * 后台登录页
	 */
    public function index(){
        header("Content-Type:text/html; charset=utf-8");
        $this->display();
    }
    /**
     * 验证码
     */
    public function code (){
    	import("ORG.Util.Image");
    	Image::buildImageVerify();
    }
    /**
     * 登录
     */
    public function login (){
        $name = $_POST['username'];
        $db = M('admin');
        if($_SESSION['verify']==md5($_POST['code'])){
            $user = $db->where(array('username'=> $name))->find();
            if($user){
                if($user['password']==md5($_POST['password'])){
                    if($user['lock']==1){
                         $_SESSION['uid'] = $user['uid'];
                         $_SESSION['uname'] = $user['username'];
                         $db->data(array('logintime'=>time()))->where(array('uid'=>$user['uid']))->save();
                         $this->success('登录成功',U('Admin/index'));
                     }else{
                        $this->error("用户被锁定，请联系管理员");
                     }
                }else{
                    $this->error('帐号或密码错误',U('index'));
                }
            }else{
                $this->error('帐号或密码错误',U('index')); 
            }
        }else{
             $this->error('验证码错误',U('index')); 
        }
    }

}